﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;

    public class DistributionRange : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected HtmlForm F2571;
        protected HtmlInputHidden hdnID;
        protected HtmlHead Head1;
        protected Label lblAlternateCarrierID;
        protected Label lblCity;
        protected Label lblContinuousWeight;
        protected Label lblContinuousWeightPrice;
        protected Label lblCounties;
        protected Label lblDistributionRange;
        protected Label lblInitialWeight;
        protected Label lblInitialWeightPrice;
        protected Label lblMsg;
        protected Label lblProvince;
        protected Label lblVendorID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtAlternateCarrierID;
        protected TextBox txtCity;
        protected TextBox txtContinuousWeight;
        protected TextBox txtContinuousWeightPrice;
        protected TextBox txtCounties;
        protected TextBox txtInitialWeight;
        protected TextBox txtInitialWeightPrice;
        protected TextBox txtProvince;
        protected TextBox txtVendorID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("DistributionRangeList.aspx?from=edit", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DistributionRangeInfo distributionRangeInfo = base.DataEntityViewState as DistributionRangeInfo;
                distributionRangeInfo.RowID = int.Parse(this.hdnID.Value);
                distributionRangeInfo.CarrierID = this.txtVendorID.Text;
                distributionRangeInfo.Province = this.txtProvince.Text;
                distributionRangeInfo.City = this.txtCity.Text;
                distributionRangeInfo.Counties = this.txtCounties.Text;
                distributionRangeInfo.InitialWeight = (this.txtInitialWeight.Text == "") ? 0M : decimal.Parse(this.txtInitialWeight.Text);
                distributionRangeInfo.InitialWeightPrice = (this.txtInitialWeightPrice.Text == "") ? 0M : decimal.Parse(this.txtInitialWeightPrice.Text);
                distributionRangeInfo.ContinuousWeight = (this.txtContinuousWeight.Text == "") ? 0M : decimal.Parse(this.txtContinuousWeight.Text);
                distributionRangeInfo.ContinuousWeightPrice = (this.txtContinuousWeightPrice.Text == "") ? 0M : decimal.Parse(this.txtContinuousWeightPrice.Text);
                distributionRangeInfo.AlternateCarrierID = this.txtAlternateCarrierID.Text;
                this.lblMsg.Text = "更新" + BaseInfoServiceClientProxy.GetInstance().Update(distributionRangeInfo, "DISTRIBUTION_RANGE") + "成功";
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void LoadData()
        {
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnID.Value = base.Request.QueryString["ID"];
                this.SetInfo2Form();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetInfo2Form()
        {
            string id = this.hdnID.Value;
            DistributionRangeInfo distributionRangeInfo = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(id, "DISTRIBUTION_RANGE") as DistributionRangeInfo;
            if (distributionRangeInfo != null)
            {
                this.txtVendorID.Text = distributionRangeInfo.CarrierID;
                this.txtProvince.Text = distributionRangeInfo.Province;
                this.txtCity.Text = distributionRangeInfo.City;
                this.txtCounties.Text = distributionRangeInfo.Counties;
                this.txtInitialWeight.Text = base.GetPreferenceDigit(distributionRangeInfo.InitialWeight);
                this.txtInitialWeightPrice.Text = base.GetPreferenceDigit(distributionRangeInfo.InitialWeightPrice);
                this.txtContinuousWeight.Text = base.GetPreferenceDigit(distributionRangeInfo.ContinuousWeight);
                this.txtContinuousWeightPrice.Text = base.GetPreferenceDigit(distributionRangeInfo.ContinuousWeightPrice);
                this.txtAlternateCarrierID.Text = distributionRangeInfo.AlternateCarrierID;
                base.DataEntityViewState = distributionRangeInfo;
            }
        }
    }
}

